<%--
    @author Duminda Dharmakeerthi
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script src="${pageContext.request.contextPath}/js/minSubDivisionUnitConvertor.js" type="text/javascript"></script>
<script type="text/javascript">
    var totalAreaInPerches = 0.0;

    $(function() {
        var he = 0,ac = 0,ro = 0,pe = 0,temp = 0;
        var cont = 2.47105381467;
        $('#hectareId').change(function() {
            changeHectare();
            calculateTotalPerches();
            $('#landExtent').val(totalAreaInPerches);
        });
        $('#acreId').change(function() {
            ac = $("#acreId").val();
            temp = parseFloat(ac % 1);
            if (temp >= 0) {
                $("#acreId").val(Math.floor(ac));
                ro = $("#roodsId").val();
                if (!$("#roodsId").val().length) {
                    ro = 0;
                }
                temp = parseFloat(ro) + (temp * 4);
                var temp2 = parseFloat(temp % 1);

                $("#roodsId").val(Math.floor(temp));
                if (temp2 >= 0) {
                    pe = $("#perchesId").val();
                    if (!$("#perchesId").val().length) {
                        pe = 0;
                    }
                    temp = parseFloat(pe) + (temp2) * 40;
                    $("#perchesId").val(temp.toFixed(4));
                }

            }
            setHect();
            calculateTotalPerches();
            $('#landExtent').val(totalAreaInPerches);
        });
        $('#roodsId').change(function() {
            ro = $("#roodsId").val();
            if (!$("#roodsId").val().length) {
                ro = 0;
            }
            temp = parseFloat(ro % 1);
            if (temp >= 0) {
                $("#roodsId").val(Math.floor(ro));
                pe = $("#perchesId").val();
                if (!$("#perchesId").val().length) {
                    pe = 0;
                }
                temp = parseFloat(pe) + (temp) * 40;
                $("#perchesId").val(temp.toFixed(4));
            }
            checkRoodsLimit();
            setHect();
            calculateTotalPerches();
            $('#landExtent').val(totalAreaInPerches);
        });
        $('#perchesId').change(function() {
            checkPerchesLimit();
            setHect();
            calculateTotalPerches();
            $('#landExtent').val(totalAreaInPerches);
        });
    });

    $(function() {
        if (parseFloat($('#landExtent').val()) > 0) {
            fillExtent();
        }
    });
</script>
<s:include value="../landDetails.jsp"/>
<div id="tabs">
    <ul>
        <li><s:a href="#land-grants-details"><s:label value="%{getText('deed_details.label')}"/></s:a></li>
        <li><s:a href="#mortgage-details"><s:label value="%{getText('mortgage_details.label')}"/></s:a></li>
        <li><s:a href="#personal-details"><s:label value="%{getText('holder_details.label')}"/></s:a></li>
        <li><s:a href="#occupier-details"><s:label value="%{getText('occupier_details.label')}"/></s:a></li>
    </ul>
    <div id="land-grants-details">
        <table class="width-100">
            <tr>
                <td><s:label value="%{getText('grant_no.label')}"/><span class="mandatory-field"></span></td>
                <td><s:textfield id="referenceNo" name="alienation.referenceNo"
                                 cssClass="width-200-px"/></td>
                <td><s:label value="%{getText('date_of_approved.label')}"/> <s:label
                        value="%{getText('date_format.label')}" cssClass="date-format"/></td>
                <td><s:textfield id="issueDate" name="alienation.issueDate"
                                 onclick="selectDate('issueDate')" cssClass="width-200-px"
                                 onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('folio_no.label')}"/></td>
                <td><s:textfield id="folioNo" name="alienation.folioNumber" cssClass="width-200-px"/></td>
                <td><s:label value="%{getText('folio_date.label')}"/> <s:label value="%{getText('date_format.label')}"
                                                                               cssClass="date-format"/></td>
                <td><s:textfield id="folioDate" name="alienation.folioDate"
                                 onclick="selectDate('folioDate')" cssClass="width-200-px"
                                 onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('folio_location.label')}"/></td>
                <td colspan="3"><s:textarea id="folioLocation" name="alienation.folioLocation"
                                            cssClass="width-595-px" rows="1"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('developed_status.label')}"/></td>
                <td colspan="3" class="left-align"><s:textarea id="developmentState"
                                                               name="alienation.developmentState"
                                                               cssClass="width-595-px" rows="1"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('comment_about_alienation.label')}"/></td>
                <td colspan="3"><s:textarea id="alienationComment" name="alienation.alienationComment"
                                            cssClass="width-595-px" rows="1"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('minimum_sub_division_unit.label')}"/></td>
                <td colspan="3">
                    <table class="width-100">
                        <tr>
                            <td><s:label value="%{getText('hectare.label')}"/></td>
                            <td colspan="5"><s:textfield id="minHectareId" name="minHectare"
                                                         cssStyle="width: 80px;" disabled="true"/></td>
                        </tr>
                        <tr>
                            <td><s:label value="%{getText('acre.label')}"/></td>
                            <td><s:textfield id="minAcreId" name="minAcre" cssStyle="width: 80px;"
                                             disabled="true"/></td>
                            <td><s:label value="%{getText('roods.label')}"/></td>
                            <td><s:textfield id="minRoodsId" name="minRoods" cssStyle="width: 80px;"
                                             disabled="true"/></td>
                            <td><s:label value="%{getText('perches.label')}"/></td>
                            <td><s:textfield id="minPerchesId" name="minPerches" cssStyle="width: 80px;"
                                             disabled="true"/></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td><s:label value="%{getText('minimum_fraction.label')}"/></td>
                <td colspan="3"><s:textfield id="minFraction" name="land.minimumFraction" cssStyle="width: 80px;"
                                             disabled="true"/></td>
            </tr>

        </table>
    </div>
    <div id="mortgage-details">
        <table class="width-100">
            <tr>
                <td><s:label value="%{getText('name_of_bank_institute.label')}"/></td>
                <td colspan="3"><s:textarea id="nameOfBank" name="alienation.mortgage.nameOfBank"
                                            cssClass="width-595-px" rows="1"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('address_of_bank_institute.label')}"/></td>
                <td colspan="3"><s:textarea id="addressOfBank" name="alienation.mortgage.addressOfBank"
                                            cssClass="width-595-px" rows="1"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('mortgage_date.label')}"/> <s:label
                        value="%{getText('date_format.label')}" cssClass="date-format"/></td>
                <td colspan="3"><s:textfield id="startedDate" name="alienation.mortgage.startedDate"
                                             onclick="selectDate('startedDate')" cssClass="width-200-px"
                                             onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('mortgage_period.label')}"/></td>
                <td><s:label value="%{getText('years.label')}"/> <s:textfield id="mortgagePeriodInYears"
                                                                              name="alienation.mortgage.mortgagePeriodInYears"
                                                                              cssStyle="width: 80px;"
                                                                              onKeyPress="return dateNumbersOnly(event,true)"/></td>
                <td><s:label value="%{getText('months.label')}"/> <s:textfield id="mortgagePeriodInMonths"
                                                                               name="alienation.mortgage.mortgagePeriodInMonths"
                                                                               cssStyle="width: 80px;"
                                                                               onKeyPress="return dateNumbersOnly(event,true)"/></td>
                <td></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('mortgage_conditions.label')}"/></td>
                <td colspan="3"><s:textarea id="conditions" name="alienation.mortgage.conditions"
                                            cssClass="width-595-px" rows="1"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('power_of_attorney.label')}"/></td>
                <td colspan="3"><s:textarea id="powerOfAttorney" name="alienation.mortgage.powerOfAttorney"
                                            cssClass="width-595-px" rows="1"/></td>
            </tr>
        </table>
    </div>
    <div id="personal-details">
        <table class="width-100">
            <s:include value="../personalDetails.jsp"/>
        </table>
    </div>
    <div id="occupier-details">
        <table class="width-100">
            <s:include value="../encroacherDetails.jsp"/>
        </table>
    </div>
</div>
<hr/>
<s:hidden name="alienation.id"/>
<s:hidden name="alienation.holder.id"/>
<s:hidden name="alienation.holder.contacts.id"/>
<s:hidden id="minimumSubDivisionUnit" name="land.minimumSubDivisionUnit"/>

<s:hidden name="land.gnDivision.id"/>
<s:hidden name="land.localAuthority.id"/>
<s:hidden name="land.village"/>
<s:hidden name="land.nameOfTheLand"/>
<s:hidden name="land.minimumFraction"/>
<s:hidden id="minExtent" name="minExtent"/>
<s:hidden id="maxExtent" name="maxExtent"/>

<s:hidden id="pls_enter_valid_no" value="%{getText('pls_enter_valid_no')}"/>
<div class="form-button-div right-align">
    <s:hidden id="grantId" name="grantId"/>
    <s:hidden id="immediateParentId" cssClass="immediateParentId" name="immediateParentId"/>
    <s:hidden name="mortgageOrTransfer" value="transfer"/>
    <s:hidden name="deedTree" value="true"/>
    <s:hidden cssClass="updateMode" name="updateMode"/>
    <%--<s:hidden name="alienation.alienationMethod.id" value="2"/>--%>
    <s:hidden name="alienationType" value="2"/>

    <s:submit id="addGrantDeed" action="saveInitialLandInformation" value="%{getText('save.label')}"
              onclick="validateLandExtent()"/>
    <input type="button" class="cancel" onclick="hideForm()"/>
    <s:hidden id="cancel" value="%{getText('cancel.label')}"/>
</div>